﻿using System;
using System.Collections.Generic;
using System.Text;
using StockTrader.DAL.IDAL.HnxInfo.Oracle;
using StockTrader.BusinessService.DataContract.HnxInfo;
using System.Data.OleDb;
using System.Data;
using StockTrader.DAL.OracleHelper;
using StockTrader.DAL.IDAL.HnxInfo;

namespace StockTrader.DAL.Oracle.HnxInfo
{
    public class OHnxTopPrice : IOHnxTopPrice
    {
        private OleDbConnection _internalConnection;
        private OleDbTransaction _internalADOTransaction = null;

        public void Open(string connString)
        {
            if (_internalConnection == null)
                _internalConnection = new OleDbConnection(connString);
            if (_internalConnection.State != ConnectionState.Open)
                _internalConnection.Open();
        }
        public void Close()
        {
            if (_internalConnection != null && _internalConnection.State != System.Data.ConnectionState.Closed)
                _internalConnection.Close();
        }

        #region Parameters
        #endregion

        #region SQL string

        private const string GET_HNX_ALLTOPPRICE = "SELECT * FROM STS_TOP3_PRICE_A WHERE NORP = '1'";


        #endregion


        #region IOHnxTopPrice Members


        public List<HnxTopPriceData> getOHnxAllTopPrice()
        {
            List<HnxTopPriceData> list = new List<HnxTopPriceData>();
            try
            {
                OleDbDataReader rdr = OleDbHelper.ExecuteReaderNoParm(_internalConnection, _internalADOTransaction, CommandType.Text, GET_HNX_ALLTOPPRICE);
                while (rdr.Read())
                {
                    list.Add(new HnxTopPriceData(
                            Convert.ToDateTime(rdr["TRADING_DATE"]),
                            Convert.ToDecimal(rdr["STOCK_ID"]),
                            Convert.ToDecimal(rdr["B_ORD_QTTY_3"]),
                            Convert.ToDecimal(rdr["B_ORD_PRICE_3"]),
                            Convert.ToDecimal(rdr["B_ORD_QTTY_2"]),
                            Convert.ToDecimal(rdr["B_ORD_PRICE_2"]),
                            Convert.ToDecimal(rdr["B_ORD_QTTY_1"]),
                            Convert.ToDecimal(rdr["B_ORD_PRICE_1"]),
                            Convert.ToDecimal(rdr["S_ORD_QTTY_1"]),
                            Convert.ToDecimal(rdr["S_ORD_PRICE_1"]),
                            Convert.ToDecimal(rdr["S_ORD_QTTY_2"]),
                            Convert.ToDecimal(rdr["S_ORD_PRICE_2"]),
                            Convert.ToDecimal(rdr["S_ORD_QTTY_3"]),
                            Convert.ToDecimal(rdr["S_ORD_PRICE_3"])));
                }
                rdr.Close();

                return list;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public int countOHnxTopPrice()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
